package com.ruoyi.web.controller.initdata;

import com.ruoyi.biz.domain.BizSingleLineAnnotation;
import com.ruoyi.biz.service.IBizSingleLineAnnotationService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.svgutils.SvgUtils1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author litao.cc
 * @version BizInitData.java v0.1 t2025/11/16 0:52
 * @date 2025/11/16 0:52
 * @description 初始化数据接口
 */
@RestController
@RequestMapping("/initdata")
public class BizInitData extends BaseController {
    @Autowired
    private IBizSingleLineAnnotationService bizSingleLineAnnotationService;
    @GetMapping(value = "/inithuxi")
    public AjaxResult inithuxi(){
        List<SvgUtils1.Line> lines = SvgUtils1.get();
        List<BizSingleLineAnnotation> annotations = new ArrayList<>();
        lines.forEach(line ->{
            BizSingleLineAnnotation annotation = new BizSingleLineAnnotation();
            annotation.setCreateTime(new Date());
            annotation.setCreateBy("system");
            annotation.setUpdateBy("system");
            annotation.setUpdateTime(new Date());
            annotation.setDeptId(200L);
            annotation.setDrawingId(1L);
            annotation.setCatenarySwitchId(-1L);
            annotation.setLineName(line.getOid());
            annotation.setLineCode(line.getOid());
            annotation.setX1(String.format("%.3f", line.getX1()));
            annotation.setY1(String.format("%.3f", line.getY1()));
            annotation.setX2(String.format("%.3f", line.getX2()));
            annotation.setY2(String.format("%.3f", line.getY2()));
            annotation.setLineType("TRACK");
            annotation.setIsTrainPlaceable("T");
            annotations.add(annotation);
        });
        bizSingleLineAnnotationService.batchInsertBizSingleLineAnnotation(annotations);
        return success(lines);
    }
}
